﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Odbc;
using System.Data;

public partial class WelcomeStudentUI : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        
        if ((String)Session["Username"] == null || (String)Session["Username"] == "admin")
        {
            //Response.End();
            Response.Redirect("~/LoginStudent.aspx");
        }

        if (Page.IsPostBack == false)
        {
            String Student_ID = (String)Session["Username"];
            String sql = "Select Feedback_ID from student WHERE Student_Email='" + Student_ID + "@iiitd.ac.in' AND Filled_Feedback=0";
            DataSet dataSet = new DataSet();
            DbUtilities dbUtil = new DbUtilities(sql);
            dataSet = dbUtil.retrieveInfo();

            dataSet.Tables[0].Columns.Add("Course");



            for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
            {
                sql = "Select Course_ID, Course_Name from course_feedback WHERE Feedback_ID=" + dataSet.Tables[0].Rows[i].ItemArray[0].ToString() + " AND Activation_Date<='" + System.DateTime.Today.ToString("yyyy-MM-dd") + "' AND End_Date>='" + System.DateTime.Today.ToString("yyyy-MM-dd") + "'";
                DataSet dataSet1 = new DataSet();
                dbUtil = new DbUtilities(sql);
                dataSet1 = dbUtil.retrieveInfo();
                if (dataSet1.Tables[0].Rows.Count == 1)
                    dataSet.Tables[0].Rows[i][1] = " " + (String)dataSet1.Tables[0].Rows[0].ItemArray[0] + " " + (String)dataSet1.Tables[0].Rows[0].ItemArray[1];

                else
                    dataSet.Tables[0].Rows[i].Delete();
            }


            FeedbackRadioButtonList.DataSource = dataSet;
            FeedbackRadioButtonList.DataTextField = "Course";
            FeedbackRadioButtonList.DataValueField = "Feedback_ID";
            FeedbackRadioButtonList.DataBind();
            //DeleteRadioButtonList.Enabled = true;
        }
    }

    protected void initiateFillFeedbackUI(object sender, EventArgs e)
    {
        if (FeedbackRadioButtonList.SelectedIndex == -1)
        {
            Response.Write("<Script language=javascript>alert('Please select an option!')</Script>");
            return;
        }

        Session["Feedback_ID"] = FeedbackRadioButtonList.SelectedItem.Value.ToString();
        Response.Redirect("~/Student/FillFeedbackUI.aspx");
    }


}